package cn.crex1.xiaomi.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.crex1.xiaomi.pojo.Product;
import cn.crex1.xiaomi.service.CategoryService;
import cn.crex1.xiaomi.service.impl.CategoryServiceImpl;

@WebServlet("/products/list")
public class CategoryController extends HttpServlet {
	private CategoryService categoryService = new CategoryServiceImpl();

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		doPost(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		Product products = new Product();
		req.setCharacterEncoding("UTF-8");
		List<Product> pslist = categoryService.selectAllClassification();
		HttpSession session = req.getSession();
		session.setAttribute("pslist", pslist);
		resp.setCharacterEncoding("UTF-8");
		resp.sendRedirect(req.getContextPath()+"/pages/index.jsp");

	}

}